package com.wxzz.elearing.pay.api.server;


import com.wxzz.elearing.pay.entity.PayLog;
import com.wxzz.elearing.pay.service.IWxPayService;
import com.wxzz.elearing.pay.service.impl.WxPayServiceSingle;
import com.wxzz.elearning.common.vo.ReturnVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/wx-pay-api")
public class WxPayApi {

    @Autowired
    private IWxPayService wxPayService;

    /**
     * 支付接口(小程序)
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "/orderPay", method = RequestMethod.POST)
    public Map orderPay(@RequestBody Map<String, String> map) {
        return wxPayService.orderPay(map);
    }

    /**
     * 支付回调(小程序)
     *
     * @return
     */
    @RequestMapping(value = "/notifyUrl", method = RequestMethod.POST)
    public void handlerNotify(HttpServletRequest request, HttpServletResponse response) throws IOException {
        wxPayService.handlerNotify(request,response);
    }

    @Autowired
    private WxPayServiceSingle wxPayServiceSingle;

    /**
     * 支付接口(pc)
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "/doUnifiedOrder", method = RequestMethod.POST)
    public Map<String, String> doUnifiedOrder(@RequestBody Map<String, String> map) {
        return wxPayServiceSingle.doUnifiedOrder(map);
    }

    /**
     * 支付回调(pc)
     *
     * @return
     */
    @RequestMapping(value = "/notifyUrlPc", method = RequestMethod.POST)
    public void notifyUrlPc(HttpServletRequest request, HttpServletResponse response) throws Exception {
        wxPayServiceSingle.notifyUrlPc(request,response);
    }

}
